﻿#include "hoteldetailscommentcontent.h"
#include "ui_hoteldetailscommentcontent.h"
#include <QDebug>

HotelDetailsCommentContent::HotelDetailsCommentContent(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HotelDetailsCommentContent)
{
    ui->setupUi(this);

    m_commentImageIndex = 0;
}

HotelDetailsCommentContent::~HotelDetailsCommentContent()
{
    delete ui;
}

void HotelDetailsCommentContent::setCommentInfo(const CommentInfo& commentInfo)
{
    m_commentID = commentInfo.getComment();
    ui->pb_reply->close();
    ui->lb_hotelComment->setText(commentInfo.getHotelComment());
    ui->lb_houseType->setText(commentInfo.getHouseType());
    ui->lb_name->setText(commentInfo.getUserName());

    QString star;
    double mark = commentInfo.getStar().toDouble();
    if (mark >= 5)
    {
        star = "★★★★★";
    }
    else if (mark >= 4)
    {
        star = "★★★★☆";
    }
    else if (mark >= 3)
    {
        star = "★★★☆☆";
    }
    else if (mark >= 2)
    {
        star = "★★☆☆☆";
    }
    else
    {
        star = "★☆☆☆☆";
    }
    ui->lb_star->setText(star);
    ui->lb_userComment->setText(commentInfo.getUserComment());

    ui->lb_inTime->setText(commentInfo.getCheckInTime() + "入住，"
                            + commentInfo.getCommentTime() + "发表");
}

void HotelDetailsCommentContent::setCommentImage(const QImage& image)
{
    switch (m_commentImageIndex)
    {
        case 0:
        {
            QPixmap pixMap = QPixmap::fromImage(image.scaled(60,60, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
            pixMap =  GlobalVars::PixmapToRound(pixMap, 30); ///30为圆形的半径
            ui->lb_image->setPixmap(pixMap);
        }  break;
        case 1: ui->lb_image1->setPixmap(QPixmap::fromImage(image.scaled(60,60))); break;
        case 2: ui->lb_image2->setPixmap(QPixmap::fromImage(image.scaled(60,60))); break;
        case 3: ui->lb_image3->setPixmap(QPixmap::fromImage(image.scaled(60,60))); break;
        case 4: ui->lb_image4->setPixmap(QPixmap::fromImage(image.scaled(60,60))); break;
        case 5: ui->lb_image5->setPixmap(QPixmap::fromImage(image.scaled(60,60))); break;
        default: break;
    }

    m_commentImageIndex++;
}

QString &HotelDetailsCommentContent::getCommentID()
{
    return m_commentID;
}

void HotelDetailsCommentContent::setRelayEnabled()
{
    ui->pb_reply->show();
}

void HotelDetailsCommentContent::on_pb_reply_clicked()
{
    emit signalRelayComment(m_commentID);
}

void HotelDetailsCommentContent::setCommentImage(const ImageList& imageList)
{
    switch (imageList.size())
    {
        default:
        case 6: ui->lb_image5->setPixmap(QPixmap::fromImage(imageList.at(5).scaled(60,60)));
        case 5: ui->lb_image4->setPixmap(QPixmap::fromImage(imageList.at(4).scaled(60,60)));
        case 4: ui->lb_image3->setPixmap(QPixmap::fromImage(imageList.at(3).scaled(60,60)));
        case 3: ui->lb_image2->setPixmap(QPixmap::fromImage(imageList.at(2).scaled(60,60)));
        case 2: ui->lb_image1->setPixmap(QPixmap::fromImage(imageList.at(1).scaled(60,60)));
        case 1:
        {
            QPixmap pixMap = QPixmap::fromImage(imageList.at(0).scaled(60,60, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
            pixMap =  GlobalVars::PixmapToRound(pixMap, 30); ///30为圆形的半径
            ui->lb_image->setPixmap(pixMap);
        }
        case 0:break;
    }

    m_commentImageIndex++;
}
